package com.component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DataServiceUtil {
	private static Logger logger = Logger.getLogger(DataServiceUtil.class);
	private static ApplicationContext appCtx = null;
	
	public static ApplicationContext getInstance() {
		if (appCtx == null) {
			appCtx = new ClassPathXmlApplicationContext("/com/data/spring/applicationContext.xml");
			setTimeTask();
		}
		return appCtx;
	}
	
	private static ScheduledExecutorService scheduExec = Executors.newSingleThreadScheduledExecutor();
	private static void setTimeTask(){
		Runnable task = new Runnable() {
			public void run() {
				try {
					PropUtil.refreshProp();
				} catch (Exception e) {
					logger.error(e.getMessage(), e);
				}
			}
		};
		scheduExec.scheduleWithFixedDelay(task, 0, 10, TimeUnit.MINUTES);
	}
}
